﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Objects;
using BAL;

public partial class Admin_UCControls_UCLoaiThe_Update : System.Web.UI.UserControl
{
    public static LoaiThe ItemLoaiThe;

    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        {
           
            ItemLoaiThe = new LoaiThe();
            ItemLoaiThe = (LoaiThe)Session["ItemLoaiThe"];

            if (ItemLoaiThe != null)
            {
                txtLoaiThe.Text = ItemLoaiThe.LoaiTheDK.ToString();
                txtTenThe.Text = ItemLoaiThe.TenThe.ToString();
                txtMoTa.Text = ItemLoaiThe.GhiChu.ToString();
            }
        }
    }

    protected void btnLuu_Click(object sender, EventArgs e)
    {
        int item = 0;

        if (CheckNull())
        {
            if (ItemLoaiThe == null)
            {
                item = BALLoaiThe.Insert_LoaiThe(txtLoaiThe.Text, txtTenThe.Text, txtMoTa.Text, 0);

            }
            else
            {
                item = BALLoaiThe.Update_LoaiThe(Int32.Parse(ItemLoaiThe.Id.ToString()), txtLoaiThe.Text, txtTenThe.Text, txtMoTa.Text, 1, Int32.Parse(ItemLoaiThe.SapXep.ToString()));

            }
        }
        if (item > 0)
        {
            lblThongbao.Visible = true;
            lblThongbao.Text = "Cập nhật thành công";

        }
        else
        {
            lblThongbao.Visible = true;
            lblThongbao.Text = "Cập nhật thất bại";
        }
    }

    protected void btnQuaylai_Click(object sender, EventArgs e)
    {
        Response.Redirect("../Admin/LoaiThe.aspx");
    }

    public bool CheckNull()
    {
        bool flag = true;
        VisibleLable();

        if (txtLoaiThe.Text == "")
        {
            lblLoaiThe.Visible = true;
            txtLoaiThe.Focus();
            flag = false;
        }

        if (txtTenThe.Text == "")
        {
            lblTenThe.Visible = true;
            txtTenThe.Focus();
            flag = false;
        }

        return flag;
    }

    public void VisibleLable()
    {
        lblTenThe.Visible = false;
        lblLoaiThe.Visible = false;
    }
    
}
